package com.woniuxy.oa.entity;

import java.util.List;

public class PageBean<T> {
	private List<T> beanList;//数据库查询
	private Integer pageIndex;//当前页，页索引，来自客户端请求
	private Integer pageSize;//每页显示的数据条数，业务规定；
	private Integer totalRecord;//总记录条数 count(*) 查询
	private Integer totalPage;//总页数，计算得
	private Integer pageBegin;
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	private Integer pageEnd;
	private String url;//请求路径参数， servlet 赋值
	@Override
	public String toString() {
		return "PageBean [beanList=" + beanList + ", \npageIndex=" + pageIndex + ", pageSize=" + pageSize
				+ ", totalRecord=" + totalRecord + ", totalPage=" + getTotalPage() + ", pageBegin=" + pageBegin
				+ ", pageEnd=" + pageEnd + "]";
	}
	public PageBean() {
		super();
		// TODO Auto-generated constructor stub
	}
	public PageBean(List<T> beanList, Integer pageIndex, Integer pageSize, Integer totalRecord, Integer totalPage, Integer pageBegin,
			Integer pageEnd) {
		super();
		this.beanList = beanList;
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		this.totalPage = totalPage;
		this.pageBegin = pageBegin;
		this.pageEnd = pageEnd;
	}
	public List<T> getBeanList() {
		return beanList;
	}
	public void setBeanList(List<T> beanList) {
		this.beanList = beanList;
	}
	public Integer getPageIndex() {
		return pageIndex;
	}
	public void setPageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getTotalRecord() {
		return totalRecord;
	}
	public void setTotalRecord(Integer totalRecord) {
		this.totalRecord = totalRecord;
	}
	public Integer getTotalPage() {
		if(totalRecord==null) {
			return null;
		}
		return totalRecord%pageSize==0?totalRecord/pageSize:(totalRecord/pageSize)+1;
	}
	public void setTotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	public Integer getPageBegin() {
		return pageBegin;
	}
	public void setPageBeginAndPageEnd() {
		//不够10页
		totalPage = getTotalPage();
		if(totalPage<10) {
			this.pageBegin=1;
			this.pageEnd = totalPage;
		}else {
			pageBegin=pageIndex-5;
			pageEnd = pageIndex+4;
			//上边界越界
			if(pageIndex-5<1){
				pageBegin=1;
				pageEnd = 10;
			}
			//下边界越界
			if(pageIndex+4>getTotalPage()) {
				pageBegin=totalPage-9;
				pageEnd = totalPage;
			}
		}
		
	}
	public Integer getPageEnd() {
		return pageEnd;
	}
	
	
}
